package cn.kgc.springcloud.controller;

import cn.kgc.springcloud.entity.City;
import cn.kgc.springcloud.service.CityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: 课工场
 * @Version: v1.0  2023/7/7
 * @Description:
 */
@RestController
@RequestMapping("city")
public class CityController {

    @Value("${server.port}")
    private String port;
    @Autowired
    private CityService cityService;
    @GetMapping
    public List<City> list(){
        System.out.println("============== port =========== " + port);
        return cityService.list();
    }


    @GetMapping("{id}")
    public City  getById(@PathVariable("id") Integer id){
        return cityService.getById(id);
    }

    @PostMapping
    public City addCity(@RequestBody City city){
        cityService.save(city);
        return city;
    }

}
